package com.mogu.comment.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.mogu.comment.service.CommentService;
import com.mogu.comment.utils.ThrowableUtils;
import com.mogu.comment.vo.CommentVo;
import com.mogu.entity.TComment;
import com.mogu.entity.TUser;
import com.mogu.message.MessageConf;
import com.mogu.message.SysConf;
import com.mogu.utils.ResultUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.validation.BindingResult;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.util.List;

@RestController
@RequestMapping("/web/comment")
@Api(value = "评论相关接口", tags = {"评论相关接口"})
public class CommentController {

    @Resource
    private CommentService commentService;

    /*-----------------------------------------------------*/
    @ApiOperation(value = "获取用户的评论列表和回复", notes = "获取评论列表和回复")
    @PostMapping("/getListByUser")
    public String getListByUser(HttpServletRequest request, @RequestBody TUser tUser) {

        //如果用户没有登录，则返回error,并返回信息token令牌未被识别
        if (request.getAttribute(SysConf.USER_UID) == null) {
            return ResultUtil.result(SysConf.ERROR, MessageConf.INVALID_TOKEN);
        }
        //获得当前登录用户的id
        String requestUId = (String) request.getAttribute(SysConf.USER_UID);
        requestUId = "76a485e7a5ff521c2353686856369bbf";
        QueryWrapper queryWrapper = new QueryWrapper();
        List<CommentVo> myCommentByUserId = commentService.findMyCommentByUserId(requestUId);
        return "";
    }

    /*-----------------------------------------------------*/
    @ApiOperation(value = "增加评论", notes = "增加评论")
    @PostMapping("/getListByUser")
    public String add(@Validated() @RequestBody TComment comment, BindingResult bindingResult) {
        //判断校验是否通过，判断bindingResult中是否有信息，利用ThrowableUtils工具类
        ThrowableUtils.checkParamArgument(bindingResult);
        return null;
    }
}
